package com.gxa.sideParking.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.sideParking.admin.mapper.CarMapper;
import com.gxa.sideParking.admin.pojo.Car;
import com.gxa.sideParking.admin.service.CarService;
import com.gxa.sideParking.core.common.JsonResult;
import com.gxa.sideParking.core.common.ResponseUtil;
import com.gxa.sideParking.core.exception.BusinessException;
import com.gxa.sideParking.core.util.R;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gxa
 * @since 2022-10-05
 */
@Service
//@Transactional
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements CarService {

    @SuppressWarnings("all")
    @Autowired
    private CarMapper carMapper;

//    @SuppressWarnings("all")
//    @Autowired
//    RedisTemplate<String,Object> redisTemplate;

//    private static final String CAR_CACHE = "car_cache:";

    R r = new R();

    @Override
    public JsonResult findAll(Integer currentPage, Integer pageSize) throws BusinessException {

        Integer start =(currentPage - 1)*pageSize;
        Integer off = pageSize;
        List<Car> findAllList = carMapper.findAll(start,off);
        return ResponseUtil.success("查询成功",findAllList);
    }

    @Override
    public JsonResult findCarNum(String carNum) throws BusinessException {
        List<Car> findCar = carMapper.findCarNum(carNum);
        return ResponseUtil.success("查询成功",findCar);
    }

    @Override
    public JsonResult findName(String userNickName) throws BusinessException {
        List<Car> name = carMapper.findName(userNickName);
        return ResponseUtil.success("查询成功",name);
    }

    @Override
    public JsonResult updateStatus(Integer carStatus) throws BusinessException {
        JsonResult status = carMapper.updateStatus(carStatus);
        return ResponseUtil.success("修改成功",status);
    }

    @Override
    public int updateForbidden(Integer carForbidden) throws BusinessException {
        int forbidden = carMapper.updateForbidden(carForbidden);
//        return ResponseUtil.success("修改成功",forbidden);
        return forbidden;
    }
}
